name: Push dev branch container to ghcr

on:
  workflow_dispatch:
  push:
    branches:
      - dev

jobs:
  dev-build-and-push:
    runs-on: [self-hosted, linux, x64]
    steps:
        - uses: actions/checkout@v4
        - uses: Swatinem/rust-cache@v2
        - name: Build the Docker image
          run: |

            # Create build container
            docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
            docker buildx create --use

            # Authenticate on registries
            docker login https://ghcr.io -u qdrant --password ${{ secrets.GITHUB_TOKEN }}

            # Build regular image for Github Registry
            GITHUB_TAG="-t ghcr.io/qdrant/qdrant:dev-${{ github.sha }} -t ghcr.io/qdrant/qdrant:dev"

            # Pull, retag and push to GitHub packages
            docker buildx build --platform='linux/amd64,linux/arm64' --build-arg GIT_COMMIT_ID=${{ github.sha }} $GITHUB_TAG --push --label "org.opencontainers.image.revision"=${{ github.sha }} .

            docker container rm -f $(docker container ls -qf "name=buildx_buildkit")
            docker volume rm $(docker volume ls -qf "name=buildx_buildkit")

